<?php

namespace app\common\model;

use think\Model;

class RemindOrder extends BaseModel
{
    protected $autoWriteTimestamp = 'int';
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';

    public function courseOrder()
    {
        return $this->hasOne(CourseOrder::class, 'course_order_id', 'course_order_id');
    }

    public function teacher()
    {
        return $this->hasOne(Teacher::class, 'teacher_id', 'teacher_id')->field('teacher_id, nickname, headeravatar, phone, year');
    }

    /**
     * 新增订单提醒
     */
    public static function add($courseOrder, $type)
    {
        $teacherId = TeacherCourse::getColumnByCourseId($courseOrder->teacher_course_id, 'teacher_id');
        //订单提醒
        $data = [
            'course_order_id' => $courseOrder->course_order_id,
            'teacher_course_id' => $courseOrder->teacher_course_id,
            'user_id' => $courseOrder->user_id,
            'teacher_id' => $teacherId ?: 0,
            'type' => $type
        ];
        self::create($data);
    }
}
